package com.jcl.tree.service;

import com.jcl.tree.dao.TreeNodeDao;
import com.jcl.tree.po.TreeNode;
import com.jcl.tree.utils.TreeBuilder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.lang.reflect.InvocationTargetException;
import java.util.List;

/**
 * @author 朝花不迟暮
 * @version 1.0
 * @date 2021/2/5 0:31
 */
@Service
public class TreeService
{
    @Autowired
    private TreeNodeDao treeNodeDao;

    public List<TreeNode> getList()
    {
        List<TreeNode> treeNodes = treeNodeDao.selectList(null);
        try
        {
            treeNodes = TreeBuilder.buildTree(treeNodes);
        } catch (InvocationTargetException e)
        {
            e.printStackTrace();
        } catch (IllegalAccessException e)
        {
            e.printStackTrace();
        } catch (NoSuchMethodException e)
        {
            e.printStackTrace();
        }
        return treeNodes;
    }
}
